package stark.app.function.speechrec;

import android.widget.CheckBox;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import stark.app.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;

/**
 * Author：daizhongbin on 2024/5/28
 * Email：1027154338@qq.com
 * Desc:
 */
public class SpeechRecAdapter extends StkProviderMultiAdapter<SpeechRecRecord> {

    private int playPos = -1;

    public void setPlayPos(int playPos) {
        if (this.playPos != playPos) {
            this.playPos = playPos;
            notifyDataSetChanged();
        }
    }

    public int getPlayPos() {
        return playPos;
    }

    public SpeechRecAdapter() {
        addItemProvider(new ItemProvider());
    }

    private class ItemProvider extends BaseItemProvider<SpeechRecRecord> {

        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_speechrec_record;
        }

        @Override
        public void convert(@NonNull BaseViewHolder holder, SpeechRecRecord record) {
            int pos = holder.getBindingAdapterPosition();
            holder.setText(R.id.tvText, record.text);
            CheckBox checkBox = holder.getView(R.id.checkbox);
            checkBox.setChecked(pos == playPos);
        }
    }

}
